<?php 

class customer extends baseDB
{
  public $mytablename='customer';
  public $Id;// int
  public $customer_name;// varchar
  public $TypeCustomer;// varchar
  public $LTD;//int
  public $Address;// varchar
  public $Pon; // varchar
  public $Fax;// varchar
  public $Site;//varchar  150
  public $LineBusiness;//varchar 200
  public $Arrived;//varchar 200
  public $notice;//text
  public $Status;//int
  public $UserContacts;//varchar 200
  public $Active;//int

public function customer($id="",$name="",$type_cusatomer="",$ltd="",$address="",$pon="",$fax="",$site="",$linebusiness="",$arrived="",$notice="",$status="",$usercontacts="",$active="")
{
	$this->Id=$id;
	$this->customer_name=$name;
	$this->TypeCustomer=$type_cusatomer;
	$this->LTD=$ltd;
	$this->Address=$address;
	$this->Pon=$pon;
	$this->Fax=$fax;
	$this->Site=$site;
	$this->LineBusiness=$linebusiness;
	$this->Arrived=$arrived;
	$this->notice=$notice;
	$this->Status=$status;
	$this->UserContacts=$usercontacts;
	$this->Active=$active;
}
  	
public function LookProfilCustomer()
{
	$this->GetCustomerInformation();
	$this->selector();
	?><div id="contectProjectOfStatus"> <?php
	$stStatus="SELECT * FROM `project_status` ";
	$queryStatus=mysql_query($stStatus) or die(mysql_error().' '.$stStatus);
	while($rowStatus=mysql_fetch_object($queryStatus))
	  {
		 
	$st="SELECT * FROM `project` WHERE `project_customer`=$this->Id AND `project_status`=$rowStatus->project_status_id";
	$query=mysql_query($st) or die(mysql_error().' '.$st);
	if(mysql_affected_rows()>0)
	 { ?><p class="admin_project_status">������ ������: <?php echo $rowStatus->project_status; ?></p> <?php 
		while($row=mysql_fetch_object($query))
		{
		  $TempProject = new project();
		  $TempProject->getby_id($row->project_id);
			?>
              <a href="http://www.restartit.co.il/IT/NewCrm/main.php?project=<?php echo $row->project_id; ?>">
                <p class="admin_project_title"><?php echo $row->project_name; ?></p> 
              </a>
		  <?php 
		  $TempProject->get_html_project();
		}
		 
	 }
	}
	 ?> </div> <?php
}
public function GetCustomerInformation()
{?>
  	<div id="content_project">
               <div id="static_info">
             	<div id="basic_info">
            		
                 	
                                          <span class="single_info">
                                          	  <span class="color_turkiz" >��"�: </span>
                                               <?php echo $this->Id; ?>
                                               .
                                          </span>
                                          
                                 
                                          <span class="single_info">
                                          	  <span class="color_turkiz">�� �����: </span>
                                             <?php   
											   echo $this->customer_name;
                                             ?>
                                             .
                                          </span>
                                             
                             
                                        <span class="single_info">
                                        	  <span class="color_turkiz">��� ����: </span>
                                           <?php   
										      if($this->TypeCustomer=='Business')
											   {
												  echo " ����";
											   }
											   else
											    {
												  echo "����";
												}
                                           ?>
                                           .
                                        </span>
                                        
                               
                                <span class="single_info">
                                	   <span class="color_turkiz" >�.�/�.�: </span>
                                     <?php 
                                          echo $this->LTD;
                                       ?>
                                       .
                                </span> 
                                 
                               
                                <span class="single_info">
                                		 <span class="color_turkiz" >�����: </span>
                                     <?php 
                                         echo $this->Address;
                                       ?>
                                       .
                                </span> 
                                <span class="single_info">
                                		 <span class="color_turkiz" >����� ����: </span>
                                     <?php 
                                         echo $this->Pon;
                                       ?>
                                       .
                                </span> 
                                <span class="single_info">
                                		 <span class="color_turkiz" >���: </span>
                                     <?php 
                                         echo $this->Fax;
                                       ?>
                                       .
                                </span> 
                                 <span class="single_info">
                                		 <span class="color_turkiz" >���� �����: </span>
                                     <?php 
                                         echo $this->LineBusiness;
                                       ?>
                                       .
                                </span> 
                                <span class="single_info">
                                		 <span class="color_turkiz" >��� ����: </span>
                                     <?php 
                                         echo $this->Address;
                                       ?>
                                       .
                                </span> 
                                <div class="info_link">
                              		<span id="customer_notice" class="color_turkiz single_info">�����: </span>
                                    <?php echo $this->notice; ?>
                                    .
            				  </div>
                    	<div class="info_link">
                             <span class="color_turkiz single_info" >��� �������: </span>
                             <a href="<?php echo  isHTTP($this->Site); ?>" target="_blank">����</a>
                             <input type="text" readonly="readonly" value="<?php echo $this->Site; ?>" /> 
                        </div>
                        <div class="info_link">
                              		<span id="customer_notice" class="color_turkiz single_info">�� �� ���� ������� �������� ����� ��: </span>
                                    <?php echo $this->GetSumBusinessOfCustomer(); ?>
                                    .
            			 </div>
                         
         </div><!--basic_info-->
             <div id="status_box" class="status_box" style="border:none;">
                  <a class="btn_a info_link " id="BtnEditCustomer">�����</a>
        	 </div><!--status_box-->
       		 </div><!--static_info--> 
             </div>
             <script>
              $(document).ready(function(e) {
                $('#BtnEditCustomer').click(function(e) {
                    get_edit_customer(<?php echo $this->Id; ?>);	
                });
            });
             </script>
             <?php  
}
public static function GetNameCustomer($id_customer)
{
             $stringCustomer_N=sprintf("SELECT * FROM `customer` WHERE Id=$id_customer");
			$queryCustomer_N=mysql_query($stringCustomer_N) or die (mysql_error().' '.$stringCustomer_N);
			
			if(mysql_affected_rows()>0)
				{
					$row=mysql_fetch_assoc($queryCustomer_N);
				     return $row['customer_name'];	
				}
			else 
				{
				 return false;	
				}	
}
public static function ifSendMailToday($date)//��� ���� ���� ����� 
{
	$st="SELECT * FROM `customer` WHERE `sendWeeklyReport`='$date'";
     $query=mysql_query($st)or die(mysql_error().' '.$st);
	 if(mysql_affected_rows()>0)
	  {
		return '1';//����� ���� ��� ���� ����
	  }
	  else  
	   {
		  
		  return '0';
	   }
}
public static function updatesendWeeklyReport($date)
{
	$st="UPDATE `customer` SET `sendWeeklyReport`='$date'";
   	 $query=mysql_query($st)or die(mysql_error().' '.$st);
	 if(mysql_affected_rows()>0)
	  {
		 
		  return '1';
	  }
	  else  
	   {
		 return '0';   
	   }
	
}
public function GetSumBusinessOfCustomer() //����� �� ���� �������� ������
{
	$st="SELECT  SUM(FinalPrice) as total FROM project WHERE
         project_customer=$this->Id 
		 AND 
		 (
		    project_status=2 
			    OR  
			project_status=3
		  )";
     $query=mysql_query($st)or die(mysql_error().' '.$st);
	 if(mysql_affected_rows()>0)
	  {
		  $row=mysql_fetch_object($query);
		  return  "  ".$row->total."  ��� ";
	  }
	  else  
	   {
		 return 0;   
	   }
  
 
}
public function selector()//���� �� ���� ����� ��� �������
{?>    
      <div id="div_selector" class="info_link">
      	<fieldset>
           <label for="from">������:</label>
          <input type="text" id="from" name="from"/>
          <label for="to">�� �����:</label>
          <input type="text" id="to" name="to"/>
          
          <select id="selector_status" name="selector_status">
               <option value="0">��� ������</option>
               <option value="1">����� �����</option>
               <option value="2">������</option>
               <option value="3">������</option>
               <option value="5">����</option>
               <option value="4">�����</option>
           </select>
           
           <a id="send_selector" name="send_selector"   >���</a>
       </fieldset>
       </div>
       <script>
        $(document).ready(function(e) {
             $('#send_selector').click(function(e) {
                
					 
							selector_all_option_project(<?php echo $this->Id; ?>,$("#selector_status").val(),
												$('#from').val(), $('#to').val());
						
				
					/* if($("#selector_status").val()!='none')/* ���� ���� �� ������*/
					   
					  	//selector_status(<?php// echo $this->project_id; ?>,$("#selector_status").val());
					
					
            });
			$(function() {
		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			changeYear: true,
			dayNamesMin: ['�', '�', '�', '�', '�', '�', '�'],
			isRTL: true,
			monthNamesShort: ['���','���','���','���','���','���','���','���','���','���','���','���'], 
			prevText: '',
			nextText: '',
			dateFormat:'yy-mm-dd',
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	});
			
        });
		
       </script> 
       
<?php }
}
?>